import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 * @author zhangyan
 * @date 2020/5/20 18:38
 */
public class Test {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new FileReader("Demo02\\stu.txt"));
        ArrayList<Student> list = new ArrayList<>();
        String line;
        while ((line = br.readLine()) != null){
            String[] split = line.split("=");
            String s1 = split[0];
            int s2 = Integer.parseInt(split[1]);
            Student s = new Student(s1,s2);
            list.add(s);
        }
        br.close();
        Collections.sort(list, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o2.getScore()-o1.getScore();
            }
        });
        BufferedWriter bw = new BufferedWriter(new FileWriter("Demo02\\stu.txt",true));
        bw.newLine();
        for (int i = 0; i < list.size(); i++) {
            bw.write(list.get(i).getName());
            bw.write("=");
            bw.write(String.valueOf(list.get(i).getScore()));
            bw.newLine();
            bw.flush();
        }
        bw.close();
    }
}
